﻿using Core.Entities.Mater;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.IO;

namespace Infrastructure.Data.Configurations.Mater
{
    /// <summary>
    /// 筒仓信息配置
    /// </summary>
    public class SiloInfoConfiguration : IEntityTypeConfiguration<SiloInfo>
    {
        public void Configure(EntityTypeBuilder<SiloInfo> builder)
        {
            // 设置表名
            builder.ToTable("BS_Silo");

            // 配置主键
            builder.HasKey(s => s.Id);

            // 属性配置
            builder.Property(s => s.Id)
                .HasColumnName("ID");

            builder.Property(s => s.SiloCode)
                .HasColumnName("SiloCode")
                .HasMaxLength(255)
                .IsRequired(false);

            builder.Property(s => s.SiloName)
                .HasColumnName("SiloName")
                .HasMaxLength(255)
                .IsRequired(false);

            builder.Property(s => s.MaterCode)
                .HasColumnName("MaterCode");

            builder.Property(s => s.MaterName)
                .HasColumnName("MaterName");

            builder.Property(s => s.WarehouseID)
                .HasColumnName("WarehouselD");

            builder.Property(s => s.WarehouseName)
                .HasColumnName("WarehouseName");

            builder.Property(s => s.LocationID)
                .HasColumnName("LocationID");

            builder.Property(s => s.LocationName)
                .HasColumnName("LocationName");

            builder.Property(s => s.Unit)
                .HasColumnName("Unit");

            builder.Property(s => s.CapacityQty)
                .HasColumnName("CapacityQty");

            builder.Property(s => s.CapacityVolumeM3)
                .HasColumnName("Capacityvolumem3");

            builder.Property(s => s.MinStockQty)
                .HasColumnName("MinStockQty");

            builder.Property(s => s.MaxStockQty)
                .HasColumnName("MaxStockQty");

            builder.Property(s => s.ReorderPointQty)
                .HasColumnName("ReorderPointQty");

            builder.Property(s => s.Manufacturer)
                .HasColumnName("Manufacturer");

            builder.Property(s => s.Model)
                .HasColumnName("Model");

            builder.Property(s => s.SerialNo)
                .HasColumnName("SerialNo");

            builder.Property(s => s.InstallDate)
                .HasColumnName("InstallDate")
                .HasColumnType("datetime2(7)");

            builder.Property(s => s.Status)
                .HasColumnName("Status");

            builder.Property(s => s.Remarks)
                .HasColumnName("Remarks");

            builder.Property(s => s.CreatedBy)
                .HasColumnName("CreatedBy");

            builder.Property(s => s.CreateTime)
                .HasColumnName("CreateTime")
                ;
            builder.Property(s => s.UpdateBy)
                .HasColumnName("UpdateBy");

            builder.Property(s => s.UpdateTime)
                .HasColumnName("UpdateTime");

            // 索引配置（可选）
            builder.HasIndex(s => s.SiloCode)
                .HasDatabaseName("IX_BS_Silo_SiloCode");

            builder.HasIndex(s => s.MaterCode)
                .HasDatabaseName("IX_BS_Silo_MaterCode");

            builder.HasIndex(s => s.LocationID)
                .HasDatabaseName("IX_BS_Silo_LocationID");

            // 软删除配置（如果需要）
             builder.HasQueryFilter(s => !s.IsDeleted);
        }
    }
}